using System.IO;


namespace miPics.Common
{

	public class ToolKit
	{
		public static int ReturnInt(string InputValue)
		{
			return ReturnInt(InputValue, 0);
		}

		public static int ReturnInt(string InputValue, int FallBack)
		{
			int ParseResult;

			if (int.TryParse(InputValue, out ParseResult)) return ParseResult;

			return FallBack;
		}

		public static short ReturnShort(string InputValue)
		{
			return ReturnShort(InputValue, 0);
		}

		public static short ReturnShort(string InputValue, short FallBack)
		{
			short ParseResult;

			if (short.TryParse(InputValue, out ParseResult)) return ParseResult;

			return FallBack;
		}

		public static string TrimToLength(string InputString, int InputLength)
		{
			string TrimString = InputString.Trim();
			int Length = (TrimString.Length < InputLength) ? TrimString.Length : InputLength;

			return InputString.Trim().Substring(0, Length);
		}

		public static void DeleteFile(string FileName)
		{
			if (File.Exists(FileName)) File.Delete(FileName);
		}

		public static string GetAltImageName(string ImageName)
		{
			return (ImageName.Trim().Length == 0)
				? "Image"
				: ImageName;
		}
	}

}